import { request, config } from "utils";
import { stringify } from "qs";
const {
  api: {
    permissionset: {
      mgtpower: { list, del, add, edit, resourceList, addResource }
    }
  }
} = config;

export function getList(params) {
  return request(`${list}?${stringify(params)}`);
}

export function addList(params) {
  return request(`${add}`, {
    method: "POST",
    body: { ...params }
  });
}
export function editList(params) {
  let par = {
    id: params.id,
    ...params.values
  };
  return request(`${edit}`, {
    method: "POST",
    body: { ...par }
  });
}

export function getDel(params) {
  const ids = params;
  return request(del, {
    method: "POST",
    body: { ids }
  });
}

/**
 * 获取角色分配资源情况
 */
export function getResourceList(params) {
  return request(`${resourceList}?${stringify(params)}`);
}

export function editResource(params) {
  let par = {
    roleId: params.roleId,
    resourceIds: params.values
  };
  return request(`${addResource}`, {
    method: "POST",
    body: { ...par }
  });
}
